import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login.vue'
import Home from '../views/Home.vue'

// 排三
import RankTree from '../components/RankThree.vue'
import RankThreeAnalysis from '../components/RankThreeAnalysis.vue'
import RankThreeScreening from '../components/RankThreeScreening.vue'
import RankThreeManual from '../components/RankThreeManual.vue'
import RankThreeResult from '../components/RankThreeResult.vue'
// 排七
import RankSeven from '../components/RankSeven.vue'
import RankSevenAnalysis from '../components/RankSevenAnalysis.vue'
import RankSevenScreening from '../components/RankSevenScreening.vue'
import RankSevenManual from '../components/RankSevenManual.vue'
import RankSevenResult from '../components/RankSevenResult.vue'

Vue.use(VueRouter)

const routes = [

  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    name: 'login',
    component: Login
  },
  {
    path: '/home',
    component: Home,
    redirect: '/rankTree',
    children: [
       { path: '/rankTree',  component: RankTree },
       { path: '/home/rankThreeAnalysis', component: RankThreeAnalysis },
       { path: '/home/rankThreeScreening', component: RankThreeScreening },
       { path: '/home/rankThreeManual', component: RankThreeManual },
       { path: '/home/rankThreeResult', component: RankThreeResult },
       { path: '/rankSeven',  component: RankSeven },
       { path: '/home/rankSevenAnalysis',  component: RankSevenAnalysis },
       { path: '/home/rankSevenScreening',  component: RankSevenScreening },
       { path: '/home/rankSevenManual',  component: RankSevenManual },
       { path: '/home/rankSevenResult',  component: RankSevenResult }
    ]
  }
  // {
  //   path: '/rankThreeAnalysis',
  //   name: 'rankThreeAnalysis',
  //   component: RankThreeAnalysis
  // },
  // {
  //   path: '/about',
  //   name: 'About',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  // }
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  if (to.path === '/login') return next()

  const tokenStr = window.sessionStorage.getItem('token')
  if (!tokenStr) {
    Vue.prototype.$message({
      type:'info',
      message:'请登录',
    })
    return next('/login')
  }
  next()
})


export default router
